package backTrack;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class YunWEI {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int M = scanner.nextInt();
        int N = scanner.nextInt();
        int[][] nums = new int[M][N];
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                nums[i][j] = scanner.nextInt();
            }
        }
        int[] minCost = new int[]{Integer.MIN_VALUE};
        bt(nums, 0, 0, nums[0][0], new ArrayList<>(), minCost);
        if (minCost[0] >= 0) {
            System.out.println(1);
        } else {
            System.out.println(-minCost[0] + 1);
        }
    }

    private static void bt(int[][] nums, int r, int c, int now, List<Integer> costList, int[] minCost) {
        if (r == nums.length - 1 && c == nums[0].length - 1) {
            int min = costList.stream().mapToInt(Integer::valueOf).min().getAsInt();
            minCost[0] = Math.max(min, minCost[0]);
        } else {
            //右走
            if (c + 1 < nums[0].length) {
                costList.add(now + nums[r][c + 1]);
                bt(nums, r, c + 1, costList.get(costList.size() - 1), costList, minCost);
                costList.remove(costList.size() - 1);
            }
            //下走
            if (r + 1 < nums.length) {
                costList.add(now + nums[r + 1][c]);
                bt(nums, r + 1, c, costList.get(costList.size() - 1), costList, minCost);
                costList.remove(costList.size() - 1);
            }
        }
    }
}
